package com.atguigu.controller;

import com.atguigu.entity.PlatformPropertyKey;
import com.atguigu.entity.PlatformPropertyValue;
import com.atguigu.result.RetVal;
import com.atguigu.service.PlatformPropertyKeyService;
import com.atguigu.service.PlatformPropertyValueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ：Hachimen
 * @date ：Created in 2021/8/24 14:29
 * @description：PlatformProperty控制类
 * @modified By：
 * @version: 0.0.1
 */
@RestController
@RequestMapping("product")
//@CrossOrigin
public class PlatformPropertyController {

    @Autowired
    private PlatformPropertyKeyService platformPropertyKeyService;

    @Autowired
    private PlatformPropertyValueService platformPropertyValueService;

    @GetMapping("getPlatformPropertyByCategoryId/{baseCategory1Id}/{baseCategory2Id}/{baseCategory3Id}")
    public RetVal getPlatformPropertyByCategoryId(@PathVariable Long baseCategory1Id,
                                                  @PathVariable Long baseCategory2Id,
                                                  @PathVariable Long baseCategory3Id) {
        List<PlatformPropertyKey> platformPropertyKeys = platformPropertyKeyService.
                getPlatformPropertyByCategoryId(baseCategory1Id,
                        baseCategory2Id,
                        baseCategory3Id);
        return RetVal.ok(platformPropertyKeys);
    }

    @GetMapping("getPropertyValueByPropertyKeyId/{propertyKeyId}")
    public RetVal getPropertyValueByPropertyKeyId(@PathVariable Long propertyKeyId) {
        List<PlatformPropertyValue> platformPropertyValues = platformPropertyValueService.getPropertyValueByPropertyKeyId(propertyKeyId);
        return RetVal.ok(platformPropertyValues);
    }

    @PostMapping("savePlatformProperty")
    public RetVal savePlatformProperty(@RequestBody PlatformPropertyKey platformPropertyKey) {
        platformPropertyKeyService.savePlatformProperty(platformPropertyKey);
        return RetVal.ok();
    }
    //通过skuID获取平台属性
    @GetMapping("getPlatformPropertyBySkuId/{skuId}")
    public List<PlatformPropertyKey> getPlatformPropertyBySkuId(@PathVariable long skuId) {
        return platformPropertyKeyService.getPlatformPropertyBySkuId(skuId);
    }
}
